home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1997-04-23 | 5.2 KB | 176 lines | [TEXT/3PRM] |
- implementation module deltaTimer;
-
- import StdClass;
- import StdInt;
- from pointer import LoadLong;
- from OS_utilities import Secs2Date, Secs2Time;
- import timerDevice;
-
-
- TicksPerSecond :== 60;
-
-
- :: CurrentTime
- :== ( !Int, // hours (0-23)
- !Int, // minutes (0-59)
- !Int // seconds (0-59)
- );
- :: CurrentDate
- :== ( !Int, // year
- !Int, // month (1-12)
- !Int, // day (1-31)
- !Int // day of week (1-7, Sunday=1, Saturday=7)
- );
-
- :: DeltaTimerHandle *s :== (TimerHandle s) -> Toolbox
- -> (TimerHandle s, !Toolbox); // for local use
-
-
- // Opening and Closing timers:
-
- OpenTimer :: !(TimerDef s (IOState s)) !(IOState s) -> IOState s;
- OpenTimer tDef ioState
- = IOStateSetDevice (IOStateSetToolbox tb1 ioState2) (TimerSystemState tHs1);
- where {
- (tHs, ioState1) = IOStateGetTimerDevice ioState;
- (tb, ioState2) = IOStateGetToolbox ioState1;
- (tHs1, tb1) = OpenTimers [tDef] tHs tb;
- };
-
-
- CloseTimer :: !TimerId !(IOState s) -> IOState s;
- CloseTimer id ioState
- = IOStateSetDevice ioState1 (TimerSystemState (TimerHandlesCloseTimer id tHs));
- where {
- (tHs, ioState1) = IOStateGetTimerDevice ioState;
- };
-
- TimerHandlesCloseTimer :: !TimerId !(TimerHandles s) -> TimerHandles s;
- TimerHandlesCloseTimer id [tH=:(tDef, sampleTime) : tHs]
- | id <> id` = [tH : TimerHandlesCloseTimer id tHs];
- = tHs;
- where {
- (id`,_,_,_) = TimerDef_Attributes tDef;
- };
- TimerHandlesCloseTimer _ tHs = tHs;
-
-
- // Enabling and Disabling of TimerDevices:
-
- EnableTimer :: !TimerId !(IOState s) -> IOState s;
- EnableTimer id ioState = SetTimers id (DeltaSetAbilityTimer Able) ioState;
-
- DisableTimer :: !TimerId !(IOState s) -> IOState s;
- DisableTimer id ioState = SetTimers id (DeltaSetAbilityTimer Unable) ioState;
-
-
- // Changing the TimerFunction and TimerInterval:
-
- ChangeTimerFunction :: !TimerId !(TimerFunction s (IOState s)) !(IOState s) -> IOState s;
- ChangeTimerFunction id f ioState = SetTimers id (DeltaSetTimerFunction f) ioState;
-
- SetTimerInterval :: !TimerId !TimerInterval !(IOState s) -> IOState s;
- SetTimerInterval id intervalTime ioState = SetTimers id (DeltaSetTimerInterval intervalTime) ioState;
-
-
- IOStateGetTimerDevice :: !(IOState s) -> (!TimerHandles s, !IOState s);
- IOStateGetTimerDevice ioState
- = (tHs, ioState1);
- where {
- (timers, ioState1) = IOStateGetDevice ioState TimerDevice;
- tHs = TimerSystemState_TimerHandles timers;
- };
-
- SetTimers :: !TimerId !(DeltaTimerHandle s) !(IOState s) -> IOState s;
- SetTimers id f ioState
- = IOStateSetDevice (IOStateSetToolbox tb1 ioState2) (TimerSystemState tHs1);
- where {
- (tHs, ioState1) = IOStateGetTimerDevice ioState;
- (tb, ioState2) = IOStateGetToolbox ioState1;
- (tHs1, tb1) = TimerHandlesSetTimer id f tHs tb;
- };
-
- TimerHandlesSetTimer :: !TimerId !(DeltaTimerHandle s) !(TimerHandles s) !Toolbox
- -> (!TimerHandles s, !Toolbox);
- TimerHandlesSetTimer id dt [tH=:(tDef, sampleTime) : tHs] tb
- | id == id` = ([tH1 : tHs ], tb1);
- = ([tH : tHs1], tb2);
- where {
- (id`,_,_,_) = TimerDef_Attributes tDef;
- (tHs1,tb2) = TimerHandlesSetTimer id dt tHs tb;
- (tH1, tb1) = dt tH tb;
- };
- TimerHandlesSetTimer _ _ tHs tb = (tHs,tb);
-
- DeltaSetAbilityTimer :: !SelectState !(TimerHandle s) !Toolbox -> (!TimerHandle s, !Toolbox);
- DeltaSetAbilityTimer able (tDef,_) tb
- = ((TimerDef_SetAbility tDef able, time), tb1);
- where {
- (time, tb1) = TickCount tb;
- };
-
- DeltaSetTimerFunction :: !(TimerFunction s (IOState s)) !(TimerHandle s) !Toolbox
- -> (!TimerHandle s, !Toolbox);
- DeltaSetTimerFunction f (tDef, sampleTime) tb = ((TimerDef_SetFunction tDef f, sampleTime), tb);
-
- DeltaSetTimerInterval :: !TimerInterval !(TimerHandle s) !Toolbox -> (!TimerHandle s, !Toolbox);
- DeltaSetTimerInterval intervalTime (tDef, sampleTime) tb
- = ((TimerDef_SetInterval tDef (Max 0 intervalTime), sampleTime), tb);
-
-
- // Suspend the interaction for a number of ticks.
-
- Wait :: !TimerInterval x -> x;
- Wait nrticks x = WaitTicks time nrticks tb x;
- where {
- (time,tb) = TickCount NewToolbox;
- };
-
- UWait :: !TimerInterval *x -> *x;
- UWait nrticks ux = WaitTicks time nrticks tb ux;
- where {
- (time,tb) = TickCount NewToolbox;
- };
-
- WaitTicks :: !Int !Int !Toolbox .x -> .x;
- WaitTicks ticks nr tb x
- | time - ticks >= nr = x;
- = WaitTicks ticks nr tb1 x;
- where {
- (time,tb1) = TickCount tb;
- };
-
-
- // Getting the blinking time:
-
- GetTimerBlinkInterval :: !(IOState s) -> (!TimerInterval, !IOState s);
- GetTimerBlinkInterval ioState = IOStateAccessToolbox (LoadLong CaretTime) ioState;
-
-
- // Get current time and date:
-
- GetCurrentTime :: !(IOState s) -> (!CurrentTime, !IOState s);
- GetCurrentTime ioState = IOStateAccessToolbox loadTime ioState;
-
- loadTime :: !Toolbox -> (!CurrentTime, !Toolbox);
- loadTime tb
- = ((hours,minutes,seconds), tb2);
- where {
- (timeLoc,tb1) = LoadLong TimeLoc tb;
- (hours,minutes,seconds,tb2) = Secs2Time timeLoc tb1;
- };
-
- GetCurrentDate :: !(IOState s) -> (!CurrentDate, !IOState s);
- GetCurrentDate ioState = IOStateAccessToolbox loadDate ioState;
-
- loadDate :: !Toolbox -> (!CurrentDate, !Toolbox);
- loadDate tb
- = ((year,month,day,dayOfWeek),tb2);
- where {
- (timeLoc,tb1) = LoadLong TimeLoc tb;
- (year,month,day,dayOfWeek,tb2) = Secs2Date timeLoc tb1;
- };
-
- CaretTime :== 756; // The address which contains the LongInt of the caret-time.
- TimeLoc :== 524; // The address which contains the time since 1-1-1904 (midnight).
-